package com.efounder.frame.baseui;

/**
 * @author zzj
 * @version 1.0.0
 */
public class BasePresenterImpl<T extends BaseContract.BaseView> implements BaseContract.BasePresenter {

    protected T mView;

    public BasePresenterImpl(T view) {
        setView(view);
    }

    /**
     * 设置一个View，子类可以复写
     */
    @SuppressWarnings("unchecked")
    protected void setView(T view) {
        this.mView = view;
        this.mView.setPresenter(this);
    }

    /**
     * 给子类使用的获取View的操作
     * 不允许复写
     *
     * @return BaseView
     */
    protected final T getView() {
        return mView;
    }

//    @Override
//    public void start() {
//        // 开始的时候进行Loading调用
//        T view = mView;
////        if (view != null) {
////            view.showLoading();
////        }
//    }

    @Override
    public void attachView() {
       // if (mView != null) {
//            view.showLoading();
//        }
    }

    @Override
    public void detachView() {
        if (mView != null) {
            mView.setPresenter(null);
        }
        mView = null;
    }

    @Override
    public boolean isViewAttached() {
        return this.mView != null;
    }
}
